package com.luhuiguo.cms.server.converter;

import org.apache.commons.beanutils.Converter;

import com.google.appengine.api.datastore.Text;

public class TextConverter implements Converter {

    @SuppressWarnings("unchecked")
    @Override
    public Object convert(Class type, Object value) {
        if (null == value) {
            return null;
        }
        if (type.equals(Text.class)) {
            if (value instanceof String) {
                String str = (String) value;
                return new Text(str);
            } else {
                return new Text(value.toString());
            }

        } else {
            if (value instanceof Text) {
                Text text = (Text) value;
                return text.getValue();
            } else {
                return value.toString();
            }
        }

    }

}
